class FruitCollection {
    private final List<Fruit> fruits = new ArrayList<>();

    public void addFruit(Fruit fruit) {
        fruits.add(fruit);
    }

    public FruitIterator createIterator() {
        return new ConcreteFruitIterator();
    }

    // 具体迭代器实现
    private class ConcreteFruitIterator implements FruitIterator {
        private int index = 0;

        @Override
        public boolean hasNext() {
            return index < fruits.size();
        }

        @Override
        public Fruit next() {
            if(hasNext()) {
                return fruits.get(index++);
            }
            return null;
        }
    }
}